/*
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  Author: hakanai
 */

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>

#include <libsdb.h>

#define TFILE "/tmp/ooxTest39ax.sdb"

static int simple_test() {
 return ((2 + 2) == 4);
}

static int header_size_test() {
  sdb_header_t header;

  memset(&header, 0, sizeof(header));

  SDB_LOGI("sizeof(sdb_header_t): %d", sizeof(sdb_header_t));
  assert(sizeof(sdb_header_t) == SDB_HEADER_SIZE);
  assert(sizeof(header) == SDB_HEADER_SIZE);

  return 0;
}

static int simple_open_write() {
  sdb_t db;

  assert(sdb_open(TFILE, &db) == SDB_OK);
  sdb_close(&db);

  return 0;
}

static int write_header_empty() {
  sdb_header_t header;
  sdb_t db;

  assert(sdb_open(TFILE, &db) == SDB_OK);
  assert(sdb_create_header(&header) == SDB_OK);
  assert(sdb_write_header(&db, &header) == SDB_OK);

  sdb_close(&db);

  return 0;
}

static int read_header_empty() {
  sdb_header_t header;
  sdb_t db;

  assert(sdb_open(TFILE, &db) == SDB_OK);
  assert(sdb_read_header(&db, &header) == SDB_OK);
  assert(header.r_num == 0);

  SDB_LOGI("header: %s", header.head);

  sdb_close(&db);

  return 0;
}

static int change_header() {
  sdb_header_t header;
  sdb_t db;

  assert(sdb_open(TFILE, &db) == SDB_OK);
  assert(sdb_read_header(&db, &header) == SDB_OK);

  sdb_close(&db);
}

int main() {
  assert(simple_test() == 1);
  assert(!header_size_test());
  assert(!simple_open_write());
  assert(!write_header_empty());
  assert(!read_header_empty());

  unlink(TFILE);
  return 0;
}

